#include <seg.h>

// 数码管显示内容的编码表：共阳极数码管，0-9，-，.
// 0-9 10 11 12 13 14 15
// 0-9 灭  A  -  P  U  C
//                                                    
//code unsigned char seg_table[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92,
//                                 0x82, 0xf8, 0x80, 0x90, 0xff, 0x88,
//0xbf,0x8c,0xc1,0xc6};//11-A,12--,13-P,14-U,15-C


unsigned char code seg_table[]={                       //标准字库
//   0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F
    0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,
//black  -     H    J    K    L    N    o   P    U     t    G    Q    r   M    y
    0x00,0x40,0x76,0x1E,0x70,0x38,0x37,0x5C,0x73,0x3E,0x78,0x3d,0x67,0x50,0x37,0x6e,
	
    0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF,0x46};    
     //0. 1. 2. 3. 4. 5. 6. 7. 8. 9. -1

		
		
		
/**
 * @brief 数码管显示函数
 * @param no 数码管编号，从0开始
 * @param what 要显示的内容，0-9
 * @param showpoint 是否显示小数点，0-不显示，1-显示
 */
void seg_display(unsigned char no,unsigned char  what,unsigned char showPoint){
    // 消隐
  P0 = 0xff;
  P2 = P2 & 0x1f | 0xe0;
  P2 &= 0x1f;

  // 位选
  P0 = 0x01 << no;
  P2 = P2 & 0x1f | 0xc0;
  P2 &= 0x1f;

  // 段选
  P0 = ~seg_table[what];
  if (showPoint) P0 &= 0x7f;
  P2 = P2 & 0x1f | 0xe0;
  P2 &= 0x1f;

}
